﻿#define _CRT_SECURE_NO_WARNINGS 

#include<stdio.h>
#include<stdlib.h>
#include<windows.h>
#include<time.h>
#include<locale.h>
#include<stdbool.h>
#include<assert.h>


//读入键
#define KEY_PRESS(VK) ((GetAsyncKeyState(VK)&0x1) ? 1 : 0)

#define WALL L'〓'
#define BODY L'〇'  //★○●◇◆□■
#define FOOD L'食'  //★○●◇◆□■

enum DIREXTION {
	UP = 1,
	DOWN,
	LEFT,
	RIGHT
};


enum GAME_STATUS {
	OK,
	KILL_WALL,
	KILL_SELF,
	END
};


//蛇身节点

typedef struct snakenode {
	int x;
	int y;
	struct snakenode* next;
}snakenode,*psnakenode;

//整条蛇

typedef struct snake {
	psnakenode psnake;
	psnakenode pfood;
	enum DIRECTION _dir;
	enum GAME_STATUS _status;
	int score;
	int foodweight;
	int sleeptime;
}snake,*psnake;



void setpos(int x, int y);

//欢迎界面
void welcome();

//绘制地图
void creatmap();

//初始化蛇
void initsnake(psnake ps);

//初始化食物
void creatfood(psnake ps);

//游戏帮助
void gamehelp();

//游戏开始准备
void gamestart(psnake ps);

//游戏运行

void gamerun(psnake ps);

//贪吃蛇移动

void snakemove(psnake ps);

//判断下一个是否是食物
int  isfood(psnakenode psn, psnake ps);

//是食物
void eadfood(psnakenode psn, psnake ps);

//不是食物
void nofood(psnakenode psn, psnake ps);

//判断死亡
int kill_by_wall(psnake ps);

int kill_by_self(psnake ps);

//游戏结束

void gameend(psnake ps);